﻿// <copyright file="RootPathBrowser.cs" company="Horiba Medical">
//     Copyright (c) Horiba Medical. All rights reserved.
// </copyright>
// <summary>
//     Recursive file finder class.
// </summary>

namespace DoxyOutParser.Parser
{
	using System.Collections.Generic;
	using System.IO;

	/// <summary>
	/// Searches for specific files recursively from a root location.
	/// </summary>
	internal class RootPathBrowser
	{
		/// <summary>
		/// Prevents a default instance of the RootPathBrowser class from being created.
		/// </summary>
		private RootPathBrowser()
		{
		}

		/// <summary>
		/// Main routine of the RootPathBrowser, search files recursively from a root directory to find those corresponding to the filter.
		/// </summary>
		/// <param name="rootDirPath">The path from where the search begins.</param>
		/// <param name="fileFilter">Which files we are searching for.</param>
		/// <returns>List of all files found.</returns>
		public static List<string> GetListOfFilesWithTypeOf(string rootDirPath, string fileFilter)
		{
			List<string> newList = new List<string>();

			DirectoryInfo rootDir = new DirectoryInfo(rootDirPath);

			FileInfo[] rootDirFiles;

			if (rootDir.Exists)
			{
				rootDirFiles = rootDir.GetFiles(fileFilter, SearchOption.AllDirectories);

				foreach (FileInfo currentFileInfo in rootDirFiles)
				{
					newList.Add(currentFileInfo.FullName);
				}
			}

			return newList;
		}
	}
}
